package com.ruoyi.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.stream.Stream;

public class ChineseUtils {

    public static void main(String[] args) throws IOException {
        StringBuffer stringBuffer = new StringBuffer();
        Stream.iterate(0, n -> n + 1).limit(100000).forEach($ -> {
            String chineseName = NameRandomUtils.getChineseName();
            String idCard = IdCardRandomUtils.generate();
            String mobile = PhoneRandomUtils.getTel();
            stringBuffer.append(chineseName.concat("\t").concat(idCard).concat("\t").concat(mobile));
            stringBuffer.append("\n");
        });
        String result = stringBuffer.toString();
        // ByteArrayInputStream bais = new ByteArrayInputStream(result.getBytes());
        // ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // byte[] buffer = new byte[1024];
        // int length;
        // while ((length = bais.read(buffer)) != -1) {
        //     baos.write(buffer, 0, length);
        // }
        String filePath = "D:\\user.txt";
        outFile(result, filePath);
    }

    public static void outFile(String data, String filePath) {
        File file = new File(filePath);
        try (FileOutputStream fop = new FileOutputStream(file)) {
            if (!file.exists()) {
                file.createNewFile();
            }
            byte[] contentInBytes = data.getBytes();
            fop.write(contentInBytes);
            fop.flush();
            fop.close();
            System.out.println("Done");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
